package com.mk.web.threadpool;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by WangChen on 2018/12/15 13:53.
 */
public class ServerThreadPool {

    public static void main(String [] args){



//        ThreadPoolExecutor pool = (ThreadPoolExecutor) Executors.newFixedThreadPool(3);
        ThreadPoolExecutor pool =  new ThreadPoolExecutor(2, 6,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(5));

        for (int i = 0; i < 12; i++){
            ClientThread clientThread = new ClientThread("client_" + i);
            pool.execute(clientThread);
        }

        pool.shutdown();
        while (!pool.isTerminated()) {
        }
        System.out.println("Finished all threads");


    }
}
